package com.five.years.common.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @ClassName getWeek
 * @Description
 * @Author zenghw
 * @Date 2020/3/23
 */
public class GetWeek {
    public static String getWeek(Date date) {
        String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        return weeks[week_index];
    }

    /**
     * 获取当前时间后七天的对应周几
     *
     * @return
     */
    public static Map<String, String> getWeekDate() {
        String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        Map<String, String> weekMap = new LinkedHashMap<>(7);
        for (int i = 1; i <= 7; i++) {
            cal.set(Calendar.DATE, cal.get(Calendar.DATE) + 1);
            int weekIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;
            if (weekIndex < 0) {
                weekIndex = 0;
            }

            weekMap.put(weeks[weekIndex], DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, cal.getTime()));
        }
        return weekMap;
    }
}
